import Vue from 'vue'


Vue.prototype.ConvertIso = function(Unix) {			//精确到时分秒
  var parts = Unix.match(/\d+/g);
  // var isoTime=new Date(parts[0]+'/'+parts[1]+'/'+parts[2]+' '+parts[3]+':'+parts[4]+':'+parts[5]).getTime();
  return parts[0]+'-'+parts[1]+'-'+parts[2]+' '+parts[3]+':'+parts[4]+':'+parts[5];
}
Vue.prototype.Convert_yearIso = function(Unix) {			//精确到年月日
  var parts = Unix.match(/\d+/g);
  // var isoTime=new Date(parts[0]+'/'+parts[1]+'/'+parts[2]+' '+parts[3]+':'+parts[4]+':'+parts[5]).getTime();
  return parts[0]+'-'+parts[1]+'-'+parts[2];
}
Vue.prototype.isoSjc = function(Unix) {			//精确到时分秒
  var parts = Unix.match(/\d+/g);
  // var isoTime=new Date(parts[0]+'/'+parts[1]+'/'+parts[2]+' '+parts[3]+':'+parts[4]+':'+parts[5]).getTime();
  return new Date(parts[0]+'/'+parts[1]+'/'+parts[2]+' '+parts[3]+':'+parts[4]+':'+parts[5]).getTime();
}

Vue.prototype.Convert_yearIso = function(Unix) {			//精确到时分秒
  var parts = Unix.match(/\d+/g);
  // var isoTime=new Date(parts[0]+'/'+parts[1]+'/'+parts[2]).getTime();
  return parts[0]+'-'+parts[1]+'-'+parts[2]
}


//时间戳转换年月日 时分秒
Vue.prototype.Convert = function(Unix) {			//精确到时分秒
  
  var Time = new Date(Unix);
  var hours,minutes,seconds;
  parseInt(Time.getHours())<10? hours='0'+Time.getHours() : hours=Time.getHours();
  Time.getMinutes()<10? minutes='0'+Time.getMinutes() : minutes=Time.getMinutes();
  Time.getSeconds()<10? seconds='0'+Time.getSeconds() : seconds=Time.getSeconds();
  return(Time.getFullYear() + "-" + (Time.getMonth() + 1) + "-" + Time.getDate()+'  '+hours+':'+minutes+':'+seconds);
}
//时间戳转换年月日
Vue.prototype.Convert_year = function(Unix) {
  var Time = new Date(Unix);
  console.log(Time.getHours())
  var hours,minutes,seconds;
  parseInt(Time.getHours())<10? hours='0'+Time.getHours() : hours=Time.getHours();
  Time.getMinutes()<10? minutes='0'+Time.getMinutes() : minutes=Time.getMinutes();
  Time.getSeconds()<10? seconds='0'+Time.getSeconds() : seconds=Time.getSeconds();
  return(Time.getFullYear() + "-" + (Time.getMonth() + 1) + "-" + Time.getDate());
}
Vue.prototype.GetDateStr = function(AddDayCount) {			//精确到时分秒
   var dd = new Date();
       dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
       var y = dd.getFullYear();
       var m = (dd.getMonth()+1)<10?"0"+(dd.getMonth()+1):(dd.getMonth()+1);//获取当前月份的日期，不足10补0
       var d = dd.getDate()<10?"0"+dd.getDate():dd.getDate();//获取当前几号，不足10补0
       //return y+"-"+m+"-"+d; 获取年月日
       return m+"-"+d;
}
// Vue.prototype.alipay = function(data,callback_success,callback_error) {		     //cordova支付宝支付
//   cordova.plugins.alipay.payment(data,			/*Data由程序提供*/
//     function success(Data){
//       callback_success && callback_success(Data);
//     },
//     function error(Data){
//       callback_error && callback_error(Data)
//     }
//   );
// }
Vue.prototype.RegExp_idCard = function(value) {    //身份证正则
    var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    if(!reg.test(value)){
       return true
    }else{
      return false
    }
}
Vue.prototype.isSystem = function() {    //身份证正则
  var u = navigator.userAgent, app = navigator.appVersion;
  var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //g
  var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  if (isAndroid) {
     //这个是安卓操作系统
     return true
  }
  if (isIOS) {
　　　//这个是ios操作系统
      return false
  }
}


Vue.prototype.vueGz = function(userId,follow,callback) {
  follow=='-1'? follow='1' : follow='-1';
  this.$post(this.$api.user.follow,{follow:follow,userId:userId}).then(data=>{
    console.log(data);
    follow=='1'? this.$toast({message:'关注成功',duration:500}) : this.$toast({message:'已取消关注',duration:500});
    callback && callback();
	});
}

Vue.prototype.vueCollect = function(targetId,targetType,cancel,callback) {
  this.$post(this.$api.user.collect,{targetId:encodeURI(targetId),targetType:targetType,collect:cancel}).then(data=>{
    cancel=='1'? this.$toast({message:'收藏成功',duration:500}) : this.$toast({message:'已取消收藏',duration:500});
    callback && callback();
	});
}

Vue.prototype.vueLike = function(targetId,targetType,thumbUp,callback) {
  thumbUp=='-1'? thumbUp='1' : thumbUp='-1';
  this.$post(this.$api.user.like,{targetId:targetId,targetType:targetType,thumbUp:thumbUp}).then(data=>{
    thumbUp=='1'? this.$toast({message:'点赞成功',duration:500}) : this.$toast({message:'已取消点赞',duration:500});
    callback && callback();
	});
}

Vue.prototype.vueBuy = function(commodityId,deal,callback) {
  this.$post(this.$api.market.buy,{commodityId:encodeURI(commodityId),deal:deal}).then(data=>{
    callback && callback(data.data.orderId);
	});
}

export default Vue;
